package com.yyt.module_main.vm;

import android.databinding.ObservableField;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.vondear.rxtool.RxTool;
import com.vondear.rxtool.view.RxToast;
import com.yyt.libsrc.bean.ApplyToCashBean;
import com.yyt.libsrc.conf.Consts;
import com.yyt.libsrc.helper.MsgHelper;
import com.yyt.libsrc.net.JavaParamsBuilder;
import com.yyt.libsrc.net.NetUtil;
import com.yyt.libsrc.net.SuccessCallback;
import com.yyt.libsrc.router.RouteTable;
import com.yyt.libsrc.router.RouterHelper;

import java.text.SimpleDateFormat;
import java.util.Date;

import top.lixb.libcommon.binding.BindingViewModel;

public class WithdrawVM extends BindingViewModel {
    public ObservableField<String> bankname = new ObservableField<>();
    public ObservableField<String> cardId = new ObservableField<>();
    public ObservableField<String> cardOwner = new ObservableField<>();
    public ObservableField<String> withdrawAmount = new ObservableField<>();
    public ObservableField<String> balance = new ObservableField<>();
    public ObservableField<String> fee = new ObservableField<>("手续费10%(预计2小时之内到账)");
    public ObservableField<String> reflect_costs = new ObservableField<>("10");
    public ObservableField<String> channelFee = new ObservableField<>("2");

    /**
     * 全部提现
     * @param view
     */
    public void withdrawAll(View view) {
        withdrawAmount.set(balance.get());
    }

    /**
     * 提交申请
     * @param view
     */
    public void commitWithdraw(View view) {
        if (!RxTool.isFastClick(2000)) {
            if (TextUtils.isEmpty(withdrawAmount.get())||Double.valueOf(withdrawAmount.get()) < 100) {
                MsgHelper.showToast("金额必须大于或等于100元");
                return;
            }
            NetUtil.sellerPost(new JavaParamsBuilder()
                    .addCmd(Consts.CMD.applyToCash)
                    .addP("type","1") //类型：1.推荐收益提现2.分红收益提现
                    .addP("amount",withdrawAmount.get())
                    .build(), new SuccessCallback<ApplyToCashBean>() {
                @Override
                public void onSuccess(ApplyToCashBean applyToCashBean) {
                    MsgHelper.showToast("提现成功");
                    Bundle bundle = new Bundle();
//                bundle.putString("accountName",applyToCashBean.data.accountName);
//                bundle.putString("bankName",applyToCashBean.data.bankName);
//                bundle.putString("bankNo",applyToCashBean.data.bankNo);
                    bundle.putString("reqSn",applyToCashBean.data.reqSn);
//                bundle.putString("amount", String.valueOf(applyToCashBean.data.amount));
//                bundle.putString("fee", String.valueOf(applyToCashBean.data.fee));
//                bundle.putString("create_at",new SimpleDateFormat("yy-MM-dd HH:mm:ss").format(new Date(applyToCashBean.sysTime)));
                    RouterHelper.getInstance().startAct(RouteTable.main_order_trace,bundle);
                }
            });
        }
    }

}
